// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 * Creator: yanking
 * Create time: 2022-02-28 18:34
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.Greedy;

import org.junit.jupiter.api.Test;

public class ValidPalindrome {
    public boolean validPalindrome(String s) {
        // 使用双指针
        int len = s.length();
        int i = 0;
        int j = s.length() - 1;
        int deleteNum = 1;
        boolean flag = true;
        while (j >= i) {
            if (s.charAt(i) != s.charAt(j)) {
                --deleteNum;
                --j;
                if (deleteNum < 0) {
                    flag = false;
                }
                continue;
            }
            ++i;
            --j;
        }
        i = 0;
        j = s.length() - 1;
        deleteNum = 1;
        while (j >= i) {
            if (s.charAt(i) != s.charAt(j)) {
                --deleteNum;
                ++i;
                if (deleteNum < 0) {
                    return false || flag;
                }
                continue;
            }
            ++i;
            --j;
        }


        return true;
    }


    @Test
    public void shout00() {
        String s = "cupupucu";
        System.out.println(validPalindrome(s));

    }
}
